
//反转链表
https://leetcode.cn/problems/reverse-linked-list/description/
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) 
    {
        if(head == nullptr) return nullptr;

        ListNode* phead = new ListNode(0,nullptr);

        while(head)
        {
            ListNode* next = phead->next;
            ListNode* tmp = head->next;
            phead->next = head;
            head->next = next;
            head = tmp;
        }

        ListNode* ret = phead->next;
        delete phead;
        return ret;
    }
};